﻿namespace LastVersionOfIpPackage.Operations
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// Sharpening class
    /// </summary>
  public class Sharpening
    {
        /// <summary>
        /// static object of this class to use this without create object
        /// </summary>
        private static Sharpening sharp = new Sharpening();

        /// <summary>
        /// mask will able it in buffer of image
        /// </summary>
        private Mask mask = new Mask();

        /// <summary>
        /// Gets or sets the sharp.
        /// </summary>
        /// <value>
        /// The sharp.
        /// </value>
        public static Sharpening Sharp
        {
            get { return Sharpening.sharp; }
            set { Sharpening.sharp = value; }
        }

        /// <summary>
        /// Makes the Sharpening.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="mySharpening">My sharpening.</param>
        /// <returns>
        /// the new image
        /// </returns>
        public Bitmap MakeSharpening(Bitmap image, Enum_needed.DetectionAndSharpingType mySharpening)
        {
            Color[,] bufferOfImage = BufferOfImage.Buffer.GetBuffer(image);
            this.mask.MaskSize = 3;
            Color[,] bufferWithPadding = LinearConvolution.LinerConvalution.AddBorder(bufferOfImage, 3);
            switch (mySharpening)
            {
                case LastVersionOfIpPackage.Enum_needed.DetectionAndSharpingType.Point:
                    this.mask.MaskValues = new double[,] { { -1, -1, -1 }, { -1, 9, -1 }, { -1, -1, -1 } };
                    break;
                case LastVersionOfIpPackage.Enum_needed.DetectionAndSharpingType.Horizontal:
                    this.mask.MaskValues = new double[,] { { 0, 0, 0 }, { 1, 1, -1 }, { 0, 0, 0 } };
                    break;
                case LastVersionOfIpPackage.Enum_needed.DetectionAndSharpingType.Vertical:
                    this.mask.MaskValues = new double[,] { { 0, 1, 0 }, { 0, 1, 0 }, { 0, -1, 0 } };                   
                    break;
                case LastVersionOfIpPackage.Enum_needed.DetectionAndSharpingType.RightDiagonal:
                    this.mask.MaskValues = new double[,] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, -1 } };
                    break;
                case LastVersionOfIpPackage.Enum_needed.DetectionAndSharpingType.LeftDiagonal:
                    this.mask.MaskValues = new double[,] { { 0, 0, 1 }, { 0, 1, 0 }, { -1, 0, 0 } };
                    break;
                default:
                    break;
            }

            try
            {
                return LinearConvolution.LinerConvalution.LinearConvolutionFn(bufferOfImage, bufferWithPadding, this.mask, Enum_needed.PostProcesses.Cutoff);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                throw ex;
            }
        }
    }
}
